<template>
	<view class="content-baisc-layout">
		<u-sticky class="header-area" :h5-nav-height="0" :bg-color="'transparent'">
			<view class="sticky-bg">
				<u-navbar title-bold :is-fixed="false" :titleSize="34" title="首页" :is-back="false"
					:border-bottom="false" :background="{
					background:'transparent'
				}" title-color="#2F3033">
					<template v-slot:left>
						<view @click="goPage('/pages/bundle/company/video')">
							<image src="https://resource.lanbaozixun.com/uploads/images/20240612104334c9f078406.png"
								mode="widthFix" class="page-logo"></image>
							<text class="md u-padding-left-20 page-text-logo pangmenzhengdao-font">蓝豹咨迅</text>
						</view>
					</template>
					<template v-slot:right>
						<!-- <image  src="../../static/images/index/customer_service.png" mode="heightFix"  class="header-customer-service u-margin-right-20"></image> -->
					</template>
				</u-navbar>
				<!-- 搜索区域 -->
				<view class="search-area">
					<view class="search-content u-flex" @click="goPage('/pages/goods_search/goods_search')">
						<u-icon name="search" size="30"></u-icon>
						<span class="nr u-padding-left-10">社保贷款首选</span>
						<image src="https://resource.lanbaozixun.com/uploads/images/202406151352450441e8481.png"
							mode="widthFix" class="icon u-margin-left-10"></image>
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="relative page-top-bg"><view class="click-area" @click="goPage('/pages/bundle/company/introduce')"></view></view>
		<view class="u-flex u-col-center u-padding-top-70 white page-top-nav-area">
			<view class="u-flex-1 u-flex-col u-col-center" @click="goPage('/yixu/pages/loan/apply')">
				<image src="https://resource.lanbaozixun.com/uploads/images/20250319221632192fd5829.png" mode="widthFix"
					class="icon-60-60"></image>
				<view class="u-padding-top-20">预估额度</view>
			</view>
			<view class="u-flex-1 u-flex-col u-col-center" @click="goPage('/yixu/pages/service/index')">
				<image src="https://resource.lanbaozixun.com/uploads/images/20250319221632608e07072.png" mode="widthFix"
					class="icon-70-51"></image>
				<view class="u-padding-top-20">合作</view>
			</view>
			<view class="u-flex-1 u-flex-col u-col-center" @click="goPage('/pages/bundle/invite_fans/invite_fans')">
				<image src="https://resource.lanbaozixun.com/uploads/images/20250319221632596324401.png" mode="widthFix"
					class="icon-64-55"></image>
				<view class="u-padding-top-20">推广</view>
			</view>
			<view class="u-flex-1 u-flex-col u-col-center" @click="goPage('/pages/user_vip/user_vip')">
				<image src="https://resource.lanbaozixun.com/uploads/images/202503192216320bf0f2930.png" mode="widthFix"
					class="icon-59-59"></image>
				<view class="u-padding-top-20">限时福利</view>
			</view>
		</view>
		<view class="nav u-margin-left-20 u-margin-right-20 u-padding-bottom-40" v-if="navList.length">
			<view class="nav-list row wrap">
				<view v-for="(item, index) in navList" :key="index" @tap="tapMenu(item)"
					class="nav-item column-center">
					<image class="nav-icon" :src="item.image"></image>
					<view class="name xs u-line-1">{{item.name}}</view>
				</view>
			</view>
		</view>
		<!-- 广告 -->
		<swipers :pid="11" height="190rpx" :isSwiper="false" padding="10rpx 20rpx 0 20rpx"></swipers>
		<!-- 资讯 -->
		<!-- 活动板块 -->
		<view class="u-margin-20 u-padding-16  activity-area">
			<image src="https://resource.lanbaozixun.com/uploads/images/2024103116130225a667159.png" mode="heightFix"
				class="title u-margin-left-8 u-margin-bottom-4 u-margin-top-8"></image>
			<view class="u-flex">
				<navigator style="width: 50%;" hover-class="none" class="u-flex-1 u-padding-right-10"
					url="/pages/tool/index?id=54">
					<u-image width="100%" height="333rpx" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/20250319213048542d32673.png"></u-image>
				</navigator>
				<view style="width: 50%;" class="u-margin-left-10">
					<navigator hover-class="none" class="u-margin-bottom-12" url="/pages/tool/index?id=46">
						<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
							src="https://resource.lanbaozixun.com/uploads/images/20241031162705939a76905.png"></image>
					</navigator>
					<navigator hover-class="none" class="u-margin-top-12" url="/pages/tool/index?id=47">
						<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
							src="https://resource.lanbaozixun.com/uploads/images/202410311635310e1455721.png"></image>
					</navigator>
				</view>
			</view>
			<view class="u-margin-top-20 gray">
				<navigator hover-class="none" class="u-flex-1" url="/pages/tool/index?id=48">
					<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/20250319213047062113609.png"></image>
				</navigator>
				<navigator hover-class="none" class="u-flex-1" url="/pages/tool/index?id=45">
					<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/20250319213047642bf8875.png"></image>
				</navigator>
				<navigator hover-class="none" class="u-flex-1" url="/pages/tool/index?id=53">
					<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/202503192130470db1a1034.png"></image>
				</navigator>
			</view>
		</view>
		<view class="u-margin-20 u-padding-16 activity-area">
			<image src="https://resource.lanbaozixun.com/uploads/images/202503192136545fee15227.png" mode="heightFix"
				class="title u-margin-left-8 u-margin-bottom-4 u-margin-top-8"></image>
			<view
				class="u-margin-top-15 bg-white u-padding-left-20 u-padding-right-20 u-padding-top-25 u-padding-bottom-10 u-border-radius-20"
				style="display: grid;grid-template-columns: repeat(3,1fr);gap: 20rpx;">
				<navigator hover-class="none" url="/pages/news_list/news_list?id=8">
					<image mode="widthFix" style="width: 100%;"
						src="https://resource.lanbaozixun.com/uploads/images/20250319215131ff4d78046.png"></image>
				</navigator>
				<navigator hover-class="none" url="/pages/news_list/news_list?id=5">
					<image mode="widthFix" style="width: 100%;"
						src="https://resource.lanbaozixun.com/uploads/images/202503192151302687f1737.png"></image>
				</navigator>
				<navigator hover-class="none" url="/pages/news_list/news_list?id=6">
					<image mode="widthFix" style="width: 100%;"
						src="https://resource.lanbaozixun.com/uploads/images/202503192151303fba94939.png"></image>
				</navigator>
			</view>
			<view class="u-flex u-margin-top-20">
				<navigator style="width: 50%;" hover-class="none" class="u-flex-1 u-padding-right-10"
					url="/pages/product_outline/product_outline">
					<u-image width="100%" height="333rpx" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/20250319215131ac3d81152.png"></u-image>
				</navigator>
				<view style="width: 50%;" class="u-margin-left-10">
					<navigator hover-class="none" class="u-margin-bottom-12" url="/pages/news_list/news_list?id=2">
						<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
							src="https://resource.lanbaozixun.com/uploads/images/20250415203129480e74488.png"></image>
					</navigator>
					<navigator hover-class="none" class="u-margin-top-12" url="/pages/news_list/news_list?id=4">
						<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
							src="https://resource.lanbaozixun.com/uploads/images/202503192151292e0ab9597.png"></image>
					</navigator>
				</view>
			</view>

			<view class="u-margin-top-20 u-flex">
				<navigator style="width: 49%;" class="u-padding-right-10" hover-class="none"
					url="/pages/news_list/news_list?id=3">
					<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/20250319215128435844911.png"></image>
				</navigator>
				<navigator style="width: 50%;" class="u-margin-left-10" hover-class="none"
					url="/pages/news_list/news_list?id=7">
					<image style="height: 156rpx;width: 100%;" mode="scaleToFill"
						src="https://resource.lanbaozixun.com/uploads/images/2025031921512980ffd2148.png"></image>
				</navigator>
			</view>
		</view>
		<view class="footer-hide bg-white u-padding-left-20 u-padding-right-20" style="position: sticky;bottom: calc(109rpx + env(safe-area-inset-bottom));">
			<view class="show-btn u-text-center u-padding-top-20" @click="toggleFooter">
				<u-icon :name="!closeFooter && showFooter ? 'arrow-down' : 'arrow-up'" color="#0ba7ec" size="28"></u-icon>
			</view>
			<view class="footer" v-show="!closeFooter && showFooter">
				<navigator url="/yixu/pages/curriculum/lists" hover-class="none">
					<image mode="widthFix" style="width: 100%"
						src="https://resource.lanbaozixun.com/uploads/images/20250319215129176615866.png"></image>
				</navigator>
				<navigator hover-class="none">
					<image mode="widthFix" style="width: 100%;"
						src="https://resource.lanbaozixun.com/uploads/images/2025031921513012aa82057.png"></image>
				</navigator>
				<a href="https://szr.lanbaozixun.com/h5/#/">
					<image mode="widthFix" style="width: 100%;"
						src="https://resource.lanbaozixun.com/uploads/images/202504152031290c6217597.png"></image>
				</a>
				<navigator url="/pages/news_list/news_list" hover-class="none">
					<image mode="widthFix" style="width: 100%;"
						src="https://resource.lanbaozixun.com/uploads/images/20250415203129959942940.png"></image>
				</navigator>
			</view>
			<view v-show="!closeFooter && showFooter" class="u-padding-top-20 u-padding-bottom-20 u-text-center bold u-tips-color"
				v-if="numberVisitors > 0">
				访问人数:{{numberVisitors||0}}
			</view>
		</view>
		<view class="partner-area" :class="{'partner-hide':scrollTop>=50}" v-show="partnerStatus">
			<u-icon name="close-circle" color="#909399" size="40" class="close-btn"
				@click="partnerStatus = false;"></u-icon>
			<image @click="toPage('/pages/bundle/partner/partner')"
				src="https://resource.lanbaozixun.com/uploads/images/20240409113318737ed7546.png" mode="widthFix"
				class="partner"></image>
		</view>
		<u-toast ref="uToast" />
		<hint-buy-vip-message ref="hintBuyVip"></hint-buy-vip-message>
		<pop-advertising pid="3"></pop-advertising>
		<common-tabbar></common-tabbar>
		<official-accounts></official-accounts>
	</view>
</template>
<script>
	import {
		getUser
	} from '@/api/user';
	import {
		mapMutations,
		mapGetters,
		mapActions
	} from "vuex";
	import {
		getHome,
		getMenu
	} from "@/api/store";
	import {
		loadingType
	} from "@/utils/type";
	import {
		loadingFun,
		menuJump,
		arraySlice,
		setTabbar,
		getRect,
		trottle,
	} from "@/utils/tools";
	import {
		toLogin
	} from "@/utils/login";
	import Cache from "@/utils/cache";
	import {
		getConfig,
		userShare,
		getNumberVisitors,
		getRegisterCoupon
	} from "@/api/app";
	import {
		queryCategoryDatas,
		queryListsDatas
	} from "@/api/course";
	const app = getApp();
	export default {
		data() {
			return {
				scrollTop: 0,
				navHeight: 0,
				page: 1,
				status: loadingType.LOADING,
				navBg: 0,
				navList: [],
				enable: true,
				isShowDownload: false,
				showPrivacyPopup: false,
				numberVisitors: 0,
				partnerStatus: true,
				closeFooter: false,
				showFooter:true
			};
		},
		async onLoad(options) {
			// #ifdef MP-WEIXIN
			wx.getPrivacySetting({
				success: (res) => {
					if (res.needAuthorization) {
						setTimeout(() => {
							uni.hideTabBar();
						}, 100);
						this.showPrivacyPopup = true;
					} else {
						uni.showTabBar();
					}
				},
				fail: (err) => {
					console.log(err);
				},
			});
			// #endif

			this.headerAction = wx.createAnimation({
				delay: 0,
				duration: 100,
				timingFunction: "ease-in-out",
			});
			this.onPageScroll = trottle(this.onPageScroll, 500, this);
			setTabbar();
			this.navHeight = app.globalData.navHeight;
			await this.getMenuFun();
			// #ifdef H5
			if (options && options.isapp == 1) {
				this.isShowDownload = true;
			}
			// #endif
			this.getNumberVisitorsFun()
		},
		async onShow() {
			this.$nextTick(function() {
				getRect(".index").then((res) => {
					if (res.top == 0) {
						this.navBg = 0;
					}
				});
			});

			// #ifdef H5
			this.enable = true;
			// #endif
			await this.getHomeFun();
			this.isLogin && this.getRegisterCouponFun();

			// #ifdef MP
			wx.getUpdateManager().onUpdateReady(function() {
				wx.showModal({
					title: "更新提示",
					content: "新版本已经准备好，是否重启应用？",
					success(res) {
						if (res.confirm) {
							wx.getUpdateManager().applyUpdate();
						}
					},
				});
			});
			// #endif
		},
		onHide() {
			// #ifdef H5
			this.enable = false;
			// #endif
		},
		onPullDownRefresh() {
			this.getHomeFun();
			this.getMenuFun();
		},
		onShareAppMessage() {
			const shareInfo = Cache.get("shareInfo");
			return {
				title: shareInfo.mnp_share_title,
				path: "pages/index/index?invite_code=" + this.inviteCode,
				imageUrl: shareInfo.mnp_share_image,
			};
		},
		onShareTimeline() {
			const shareInfo = Cache.get('shareInfo')
			return {
				title: shareInfo.mnp_share_title,
				path: "pages/index/index?invite_code=" + this.inviteCode,
				imageUrl: shareInfo.mnp_share_image,
			};
		},
		onPageScroll(e) {
			const top = uni.upx2px(100);
			const {
				scrollTop
			} = e;
			if (!this.enable) return;
			let percent = scrollTop / top;
			this.navBg = percent > 1 ? 1 : percent;
			this.scrollTop = scrollTop;
			if(scrollTop >= 50)this.showFooter = false;
			else this.showFooter = true
		},
		methods: {
			...mapMutations(["SETCONFIG"]),
			...mapActions(["getCartNum", "getUser"]),
			async getNumberVisitorsFun() {
				let {
					code,
					data
				} = await getNumberVisitors();
				if (code == 1) this.numberVisitors = data;
			},
			async handleRetry() {
				try {
					const {
						code,
						data
					} = await getConfig();
					if (code == 1) {
						this.SETCONFIG(data);
						setTabbar();
					}
				} catch (e) {
					uni.showTabBar();
				}
				this.getShareInfo();
				this.getUser();
			},
			async getShareInfo() {
				const {
					code,
					data
				} = await userShare();
				if (code == 1) {
					Cache.set("shareInfo", data);
				}
			},
			async getHomeFun() {
				const {
					code,
					data
				} = await getHome();
				uni.stopPullDownRefresh();
			},
			async getMenuFun() {
				const {
					code,
					data
				} = await getMenu({
					type: 1,
				});
				uni.stopPullDownRefresh();
				if (code == 1) {
					this.navList = data;
				}
			},
			async tapMenu(item) {
				if (item.link_type == 3) {
					return this.exploitation()
				}
				if (!this.isLogin) return toLogin();
				if (item.type == 0) {
					uni.showLoading({
						title: '加载中'
					});
					getUser().then(res => {
						uni.hideLoading();
						if (res.code == 1) {
							if (res.data.is_vip == 0) {
								this.$refs.hintBuyVip.show()
								return false
							}
							menuJump(item);
						} else {
							this.$refs.uToast.show({
								title: '系统错误，请稍后重试',
								type: 'error'
							})
						}
					})
				} else {
					menuJump(item);
				}
			},
			goPage(url) {
				if (!this.isLogin) return toLogin();
				uni.navigateTo({
					url,
					fail: (e) => {
						console.log(e)
					}
				});
			},
			getRegisterCouponFun() {
				getRegisterCoupon().then((res) => {
					if (res.code == 1) {
						if (res.data && res.data.length) {
							this.showCoupop = true;
						}
						this.couponPopList = res.data;
					}
				});
			},
			errorToast(e) {
				this.$refs.uToast.show({
					title: e,
					type: 'error'
				})
			},
			showBuyVip() {
				this.$refs.hintBuyVip.show();
			},
			toPage(e) {
				uni.navigateTo({
					url: e
				})
			},
			exploitation() {
				this.$u.toast('功能升级中');
			},
			toggleFooter() {
				if(!this.closeFooter){
					this.showFooter = true
				}
				this.closeFooter = !this.closeFooter;
			}
		},
		computed: {
			...mapGetters(["inviteCode", "appConfig"]),
			seting() {
				const {
					index_setting
				} = this.appConfig;
				return index_setting;
			}
		}
	};
</script>
<style lang="scss">
	@import './index.scss';
</style>